package com.lc.schedule.dao.impl;

import com.lc.schedule.dao.BaseDao;
import com.lc.schedule.dao.SysScheduleDao;
import com.lc.schedule.pojo.SysSchedule;

import java.util.List;

/**
 * @author liuchun
 */
public class SysScheduleDaoImpl extends BaseDao implements SysScheduleDao {
    @Override
    public int addSchedule(SysSchedule sysSchedule) {
        String sql  = "insert into sys_schedule values(default,?,?,?)";
        int rows = baseUpdate(sql, sysSchedule.getUid(), sysSchedule.getTitle(), sysSchedule.getCompleted());
        return rows;
    }

    @Override
    public List<SysSchedule> findAll(SysSchedule sysSchedule) {
        String sql = "select * from sys_schedule";
        List<SysSchedule> list = baseQuery(SysSchedule.class, sql);
        return  list;
    }

    @Override
    public List findSchedule(int uid) {
        String sql = "select * from sys_schedule where uid = ?";
        List list = baseQuery(SysSchedule.class, sql, uid);
        return list;
    }

    @Override
    public Integer addScheduleByUser(int uid) {
        String sql = "insert into sys_schedule values(default,?,'请添加日程',0)";
         return baseUpdate(sql,uid);
    }

    @Override
    public Integer UpdateItem(SysSchedule sysSchedule) {
        String sql = "update sys_schedule set title = ? ,completed = ? where sid = ?";
        return baseUpdate(sql,sysSchedule.getTitle(),sysSchedule.getCompleted(),sysSchedule.getSid());
    }

    @Override
    public Integer deleteSchedule(SysSchedule sysSchedule) {
        String sql = "delete from sys_schedule where sid = ?";
        return baseUpdate(sql,sysSchedule.getSid());
    }
}
